package com.ybl.store.backend.controller;

import com.ybl.store.backend.dto.UserInfoDTO;
import com.ybl.store.backend.dto.req.LoginReqDTO;
import com.ybl.store.backend.dto.resp.LoginRespDTO;
import com.ybl.store.backend.service.LoginService;
import com.ybl.store.common.convention.result.Result;
import com.ybl.store.common.convention.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 后台管理控制层
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/backend")
public class LoginController {

    private final LoginService loginService;

    /**
     * 后台管理登录
     */
    @PostMapping("/login")
    public Result<LoginRespDTO> login(@RequestBody LoginReqDTO requestParam) {
        return Results.success(loginService.login(requestParam));
    }

    /**
     * 获取当前登录用户信息
     */
    @GetMapping("/user-info")
    public Result<UserInfoDTO> getUserInfo() {
        return Results.success(loginService.getUserInfo());
    }

    /**
     * 后台管理登出
     */
    @PostMapping("/logout")
    public Result<Void> logout() {
        return Results.success();
    }
}
